import 'package:flutter/material.dart';
import 'package:flutter_jojo_test/common/base/base_container.dart';
import 'package:flutter_jojo_test/common/resource/color.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:video_player/video_player.dart';

import 'logic.dart';

class HomePage extends StatefulWidget {
  @override
  State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage>
    with AutomaticKeepAliveClientMixin {
  final logic = Get.put(HomeLogic());

  final state = Get.find<HomeLogic>().state;

  @override
  Widget build(BuildContext context) {
    print("HOME:build");
    return Obx(() => BaseContainer(children: [
          PageView.builder(
            itemCount: state.data.length,
            itemBuilder: (context, index) {
              return Obx(() => Column(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: [
                      SizedBox(
                        child: logic.videoUtils.hasData.value
                            ? VideoPlayer(logic.videoUtils.list[index] ??
                                VideoPlayerController.network(''))
                            : Container(),
                        width: Get.width,
                        height: logic.height(index),
                      ),
                    ],
                  ));
            },
            scrollDirection: Axis.vertical,
            controller: state.pageController,
          ),
        ], color: ThemeColor.g1.value, statusDark: true));
  }

  @override
  // TODO: implement wantKeepAlive
  bool get wantKeepAlive => true;
}
